<!-- 
@name: 收藏
-->
<template>
	<div id="coupon" class="page">

		<div class="content-wrap">

			<div class="diy-area">
				<div class="like">

					<div class="type2" ref='type2Scorll' id='type2Scorll'>
						<van-list v-model="loading" offset='0' :finished="finished" finished-text="没有更多了" @load="onLoad">
							<div @click="goCouponDetail(goodsItem.goodsOnList.pkey)" v-for="(goodsItem, goodsIndex) in likeList" :key="goodsIndex">
								<van-swipe-cell>
									<div class="item flex-row flex-center">
										<img object-fit="fill" :src="goodsItem.goodsOnList.photo[0]"></img>
										<div style="flex:1">
											<div class="text1">{{goodsItem.goodsOnList.name}}</div>
											<div class="flex-row flex-alignCenter">
												<div class="text3">{{goodsItem.goodsOnList.applauseRate}}%好评</div>
												<div class="text4" v-if="goodsItem.showType&&goodsItem.showType.indexOf('显示销量') !=-1">已售{{goodsItem.goodsOnList.xsNumTotal}}</div>
											</div>
											<div class="flex-between flex-alignCenter" style="margin-top: 0.2rem;">
												<div class="text2">
													{{goodsItem.goodsOnList.price}} </div>
												<div>
													<van-button class="button" @click.stop="goCouponDetail(goodsItem.goodsOnList.pkey,'',goodsItem.goodsOnList)">立即购买</van-button>
												</div>
											</div>
										</div>
									</div>
									<template #right>
										<van-button square text="删除" @click="del(goodsItem.goods)" style="height:100%" type="danger" class="delete-button" />
									</template>
								</van-swipe-cell>
							</div>

						</van-list>

					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
export default {
	name: 'app',
	components: {},
	data() {
		return {
			searchValue: '',
			searchTypeIndex: '',
			getGtypeList: [],
			listModel: true, //true 列表模式 false 大图模式
			searchTypeList: [
				{ value: '销量最高', pkey: 'XS' },
				{ value: '距离最近', pkey: 'NEAR' },
				{ value: '评分最高', pkey: 'RATE' },
			],
			searchData: {
				page: 0,
				pagesize: 5,
				// sortType: 'XS', //XS 销量,NEAR 距离,RATE 评分
				// lng: this.$store.state.lng,
				// lat: this.$store.state.lat,
			},
			likeList: [],
			activeName: '',
			loading: false,
			finished: false,
		};
	},

	created() {
		if (this.$route.query.pkey) {
			//跳转过来的分类pkey
			this.activeName = Number(this.$route.query.pkey);
		}
		this.getGtype_goods();
	},
	methods: {
		del(pkey) {
			var params = { goodsPkey: pkey };

			this.$myApi.delCollect_goods(params).then((res) => {
				if (res.code == 0) {
					this.$notify({ type: 'success', message: '操作成功' });

					this.onClick();
				} else {
				}
			});
		},
		goCouponDetail(pkey) {
			// console.log()
			this.$router.push({
				path: '/coupon/detail',
				query: { pkey: pkey },
			});
		},
		sortChange(pkey) {
			this.searchData.sortType = pkey;
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		onLoad() {
			console.log('触底');
			this.getData();
		},
		onClick() {
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		getGtype_goods() {
			this.$myApi.getGtype_goods().then((res) => {
				if (res.code == 0) {
					var arr = [{ name: '全部', pkey: '' }, ...res.result];
					this.getGtypeList = arr;
				} else {
				}
			});
		},
		getData(finished) {
			// finished 避免清空列表出发刷新
			var params = this.searchData;
			params.gtype = this.activeName;
			this.$myApi.collectList_goods(params).then((res) => {
				if (res.code == 0) {
					this.likeList = [...this.likeList, ...res.result.content];
					this.loading = false;
					this.searchData.page++;
					if (finished) {
						this.finished = false;
					}
					if (res.result.content.length < 5) {
						this.finished = true;
					}
				} else {
				}
			});
		},
		clearSearch() {
			this.likeList = [];
			this.searchData.page = 0;
			this.searchData.pagesize = 5;
			this.finished = false;
		},
		onSearch(e) {
			console.log(e);
			this.clearSearch();
			this.searchData.title = e;
			this.finished = true;
			this.getData(true);
		},
		onCancel() {},
	},
};
</script>
<style lang="less" scoped>
#coupon {
	padding-left: 0rem;
	padding-right: 0rem;
	min-height: calc(100vh - 46px);
	background-color: #fafafa;

	position: relative;
	.van-swipe__indicators {
		bottom: 25px;
	}
	.van-search__content {
		border-radius: 20px;
	}
	.searchWrap {
		width: 100%;
	}
	.searchHistory {
		padding: 0.25rem;
		background-color: #fff;
		img {
			height: 0.28rem;
			width: 0.32rem;
		}
		.text1 {
			font-size: 0.28rem;
			font-weight: bold;
			color: #333333;
			margin-bottom: 0.2rem;
		}
		.text2 {
			background: #f5f5f5;
			border-radius: 5px;
			padding: 0.16rem 0.3rem;
			margin-right: 0.12rem;
			margin-bottom: 0.12rem;
			white-space: nowrap;
			display: inline-block;
			font-size: 0.24rem;
			color: #666666;
		}
		.text3 {
			.text2();
			color: #999999;
		}
	}
	.content-wrap {
		width: 100%;
		height: auto;
		.diy-area {
			// background-color: #fff;
			position: relative;
			background-color: inherit;

			img {
				vertical-align: top;
			}

			.banner {
				.bannerImg {
					height: 4rem;
					width: 100%;
				}
			}
			.br {
				height: 0.2rem;
				width: 100%;
				background: #fafafa;
			}
			.likeTitle {
				font-size: 0.32rem;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
				margin-bottom: 0.24rem;
				text-align: center;
			}
			.like {
				padding: 0.24rem;
				// max-height: 200px;
				position: relative;
				box-sizing: border-box;
				border-radius: 10px;
				.button {
				background: #eca73b;
					border-radius: 20px;
					font-size: 0.22rem;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ffffff;
					padding: 0.1rem 0.2rem;
					height: auto;
				}
				.type1 {
					width: 100%;
					overflow-x: scroll;
					height: 7.7rem;
					padding-bottom: 1rem;
					img {
						height: 3rem;
						width: 100%;
						border-radius: 10px;
					}
					.item {
						margin-bottom: 8px;
						background: #fff;

						border-radius: 10px;
						.text1 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #000000;
							text-overflow: ellipsis;
							white-space: nowrap;
							overflow: hidden;
							margin-bottom: 0.2rem;
						}
						.text2 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
						}
						.text3 {
							background: rgba(255, 212, 49, 0.12);
							border-radius: 2px;
							font-size: 0.24rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							padding: 0.07rem 0.17rem;
							margin-right: 0.23rem;
						}
						.text4 {
							font-size: 0.22rem;
							font-family: PingFang SC;
							font-weight: 500;
							color: #666666;
							margin-right: 0.23rem;
						}
					}
				}
				.type2 {
					width: 100%;
					overflow-x: scroll;
					height: 100%;
					padding-bottom: 1rem;
					img {
						height: 1.8rem;
						width: 1.8rem;
						margin-right: 0.24rem;
						border-radius: 10px;
					}
					.item {
						margin-bottom: 8px;
						background: #fff;
						padding: 0.24rem;
						border-radius: 10px;
						.text1 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #000000;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							margin-bottom: 0.2rem;
						}
						.text2 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
						}
						.text3 {
							background: rgba(255, 212, 49, 0.12);
							border-radius: 2px;
							font-size: 0.24rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							padding: 0.07rem 0.17rem;
							margin-right: 0.23rem;
						}
						.text4 {
							font-size: 0.22rem;
							font-family: PingFang SC;
							font-weight: 500;
							color: #666666;
							margin-right: 0.23rem;
						}
					}
				}
			}
			.iconWrap {
				position: relative;
				padding-bottom: 0.55rem;
				border-radius: 20px 20px 0 0;
				top: -0.3rem;
				// margin-top: -0.4rem;
				background-color: #fafafa;
				z-index: 999;
				display: grid;
				grid-template-columns: repeat(4, 25%);
				.iconImg {
					width: 0.8rem;
					height: 0.8rem;
					margin-bottom: 0.12rem;
				}
				.item {
					-webkit-box-flex: 1;
					flex: 1;
					margin-top: 0.3rem;
					font-size: 0.24rem;
					text-align: center;
				}
			}
		}
	}
}
</style>
<style lang="less" scoped>
/deep/.van-search .van-cell {
	padding-top: 0.2rem;
	padding-bottom: 0.2rem;
	font-size: 0.28rem;
}
/deep/.van-tab {
	// flex: 0 1 auto;
	// width: 1rem;
	font-size: 0.3rem;
}
/deep/.van-tab--active {
	font-weight: bold;
	font-size: 0.32rem;
}
</style>